package com.testerhome.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * @author sunliancheng
 * @date 2023/10/22
 */
public class LoginPage {
    private WebDriver webDriver;
    //构造方法
    public LoginPage(WebDriver webDriver){
        this.webDriver = webDriver;
    }
    public IndexPage login(String userName, String password){
        SelfLogger.info("login开始执行了, userName:" + userName);
        //2. 导航到登录页
        webDriver.get("https://testerhome.com/account/sign_in");

        //3.输入账号
        webDriver.findElement(By.id("user_login")).sendKeys(userName);

        //4.输入密码
        webDriver.findElement(By.id("user_password")).sendKeys(password);

        //5.点击登录
        webDriver.findElement(By.name("commit")).click();

        //6. 校验登录成功
        try {
            Thread.sleep(1000*3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        String source = webDriver.getPageSource();
        assertThat(source).contains("提高自己的知名度，请添加个有个性的头像吧");
        return new IndexPage(webDriver);
    }
}
